package team2.arsystem.Controller;

import java.util.ArrayList;
import java.util.Date;

import team2.arsystem.DomainObjects.Account;
import team2.arsystem.DomainObjects.DebitTransaction;
import team2.arsystem.GUI.AddToDebitAccount;
/*This class is the other use case controller. This will handle requests related to debit and credit transactions. This class is again a Singleton.*/
public class TransactionController {
	
	private static TransactionController transactionController=new TransactionController();
	//private static DebitTransaction debitObject = new DebitTransaction();
	 
	 public TransactionController() 
	 {
	 }
	 
	 public static TransactionController getTransactionController()
	 {
		return transactionController;
		
	 }
	 
	/*Transaction Controller needs the Account Controller(to get the username) and the Debit Transaction objects.*/
	public AccountController getAccountController()
	{
		return AccountController.getAccountController();
	}
	
	private DebitTransaction getDebitTransactionObject()
	{
		return DebitTransaction.getDebitTransactionObject();
	}
	
	/*The following methods call the appropriate methods in the DebitTransaction class to perform the requested operation.*/
	public boolean addDebitTx(Object[] debitTxInformation)
	{
		try
		{
		return (getDebitTransactionObject().addDebitTransaction((String)debitTxInformation[0],Double.parseDouble(debitTxInformation[1].toString()),Boolean.parseBoolean(debitTxInformation[2].toString()), (Date)debitTxInformation[3], (Date)debitTxInformation[4], (String)debitTxInformation[5]));
		}
		catch(Exception e)
		{
		  e.printStackTrace();
		  return false;
		}
		
	}
	
	public ArrayList<ArrayList<String>> getDebitReminders()
	{
		try
		{
		return (getDebitTransactionObject().getDebitReminders(AccountController.getAccountController().getAccountObject().getAccountUserName()));
		}
		catch(Exception e)
		{
		  e.printStackTrace();
		  return null;
		}
	}
	
	public String getUserName()
	{
		return AccountController.getAccountController().getUserName();
		
	}
}
